﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ffmpegVideoInfo
{
    class Program
    {
        static void Main(string[] args)
        {
            string ffmpeg = @"f:\ffmpeg.exe";
            string arg = @"-i f:\jiaoxiangyue.mov";
            System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo();
            processStartInfo.FileName = ffmpeg;
            processStartInfo.Arguments = arg;
            processStartInfo.RedirectStandardOutput = false;
            processStartInfo.RedirectStandardError = true;

            processStartInfo.UseShellExecute = false;
            System.Diagnostics.Process process = new System.Diagnostics.Process();
           
            process.StartInfo = processStartInfo;
            process.Start();
            string str = "";
            using (var standardOutPut = process.StandardError)
            {
                 str = standardOutPut.ReadToEnd();
                // Duration: 00:04:35.80, start: 0.000000, bitrate: 402676 kb/s
            }

            string d = "Duration: ";
            int durationIndex = str.IndexOf(d);
            var durationStr = str.Substring(durationIndex + d.Length);
            int startIndex = durationStr.IndexOf(", start: ");
            var time = durationStr.Substring(0, startIndex);
            Console.WriteLine(time);
            
            TimeSpan t = TimeSpan.ParseExact(time, "hh\\:mm\\:ss\\.ff", CultureInfo.InvariantCulture);
            Console.Read();
        }
    }
}
